package com.alibaba.sample.kantiezi.biz.user.ao;

import com.alibaba.biz.command.ao.ApplicationObjectSupport;
import com.alibaba.biz.command.result.Result;
import com.alibaba.biz.command.result.ResultSupport;

import com.alibaba.common.lang.StringUtil;

import com.alibaba.sample.kantiezi.dal.dataobject.User;
import com.alibaba.sample.kantiezi.biz.user.manager.UserManager;

public class ViewUser extends ApplicationObjectSupport {
    private UserManager userManager;
    private String      userId;

    public void setUserManager(UserManager userManager) {
        this.userManager = userManager;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public void afterPropertiesSet() throws Exception {
        if (StringUtil.isEmpty(userId)) {
            throw new IllegalArgumentException("missing userId");
        }
    }

    public Result execute() {
        Result result = new ResultSupport();
        User   user   = userManager.getUser(userId);

        result.setDefaultModel(user);

        return result;
    }
}
